package com.example.gobang.mapper;

import com.example.gobang.model.UserInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface UserMapper {
    // 注册
    @Insert("insert into user_info (user_name, password, score, total_count, win_count) values ( #{userName}, #{password}, 100, 0, 0);")
    int insert(UserInfo userInfo);

    // 根据用户名查询
    @Select("select * from user_info where user_name = #{userName}")
    UserInfo selectByName(String userName);

    // 胜利，比赛场数 + 1，获胜场数 + 1，天梯分数 + 30
    @Update("update user_info set total_count = total_count + 1, win_count = win_count + 1, score = score + 30 where user_id = #{userId}")
    void userWin(int userId);

    // 失败，比赛场数 + 1，天梯分数 - 30
    @Update("update user_info set total_count = total_count + 1, score = score - 30 where user_id = #{userId}")
    void userLose(int userId);

}
